package com.zenithmind.library.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 罚金记录视图对象
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Data
@Schema(name = "罚金记录视图对象", description = "罚金记录信息的视图对象")
public class FineRecordVO {

    @Schema(description = "罚金记录ID")
    private String id;

    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "用户姓名")
    private String userName;

    @Schema(description = "用户学号/工号")
    private String userNumber;

    @Schema(description = "借阅记录ID")
    private String borrowRecordId;

    @Schema(description = "图书标题")
    private String bookTitle;

    @Schema(description = "图书ISBN")
    private String bookIsbn;

    @Schema(description = "罚金类型")
    private Integer fineType;

    @Schema(description = "罚金类型名称")
    private String fineTypeName;

    @Schema(description = "罚金金额")
    private BigDecimal fineAmount;

    @Schema(description = "已支付金额")
    private BigDecimal paidAmount;

    @Schema(description = "未支付金额")
    private BigDecimal unpaidAmount;

    @Schema(description = "支付状态")
    private Integer paymentStatus;

    @Schema(description = "支付状态名称")
    private String paymentStatusName;

    @Schema(description = "支付方式")
    private String paymentMethod;

    @Schema(description = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime paymentTime;

    @Schema(description = "支付凭证号")
    private String paymentReference;

    @Schema(description = "罚金说明")
    private String description;

    @Schema(description = "操作员ID")
    private String operatorId;

    @Schema(description = "操作员姓名")
    private String operatorName;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 获取罚金类型名称
     */
    public String getFineTypeName() {
        if (fineType == null) {
            return "未知";
        }
        return switch (fineType) {
            case 1 -> "逾期罚金";
            case 2 -> "损坏赔偿";
            case 3 -> "丢失赔偿";
            default -> "未知";
        };
    }

    /**
     * 获取支付状态名称
     */
    public String getPaymentStatusName() {
        if (paymentStatus == null) {
            return "未知";
        }
        return switch (paymentStatus) {
            case 0 -> "未支付";
            case 1 -> "已支付";
            case 2 -> "部分支付";
            default -> "未知";
        };
    }

    /**
     * 计算未支付金额
     */
    public BigDecimal getUnpaidAmount() {
        if (fineAmount == null) {
            return BigDecimal.ZERO;
        }
        if (paidAmount == null) {
            return fineAmount;
        }
        return fineAmount.subtract(paidAmount);
    }

    /**
     * 判断是否已完全支付
     */
    public boolean isFullyPaid() {
        return paymentStatus != null && paymentStatus == 1;
    }

    /**
     * 判断是否为逾期罚金
     */
    public boolean isOverdueFine() {
        return fineType != null && fineType == 1;
    }

    /**
     * 判断是否为损坏赔偿
     */
    public boolean isDamageFine() {
        return fineType != null && fineType == 2;
    }

    /**
     * 判断是否为丢失赔偿
     */
    public boolean isLostFine() {
        return fineType != null && fineType == 3;
    }
}
